package com.mes.web.controller.biz;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.mes.common.annotation.Log;
import com.mes.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.mes.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mes.common.enums.BusinessType;
import com.mes.common.utils.poi.ExcelUtil;
import com.mes.framework.cache.DictUtils;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.mes.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.mes.biz.domain.BizStock;
import com.mes.biz.service.BizStockService;

/**
 * 商品库存Controller
 * @author wy
 * @email wy
 * @date 2023-05-24
 */
@RestController
@RequestMapping("/biz/bizStock")
public class BizStockController extends BaseController {

    @Autowired
    private BizStockService bizStockService;

    /**
     * 查询商品库存列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizStock:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BizStock bizStock, HttpServletRequest request, HttpServletResponse response) {
        bizStock.setPage(new PageDomain(request, response));
        return R.data(bizStockService.findPage(bizStock));
    }

    /**
     * 获取商品库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizStock:query')")
    @GetMapping(value = "/{id}")
    public R<BizStock> detail(@PathVariable("id") String id) {
        return R.data(bizStockService.get(id));
    }

    /**
     * 新增商品库存
     */
    @PreAuthorize("@ss.hasPermi('biz:bizStock:add')")
    @Log(title = "商品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BizStock bizStock) {
        return R.status(bizStockService.save(bizStock));
    }

    /**
     * 修改商品库存
     */
    @PreAuthorize("@ss.hasPermi('biz:bizStock:edit')")
    @Log(title = "商品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizStock bizStock) {
        return R.status(bizStockService.save(bizStock));
    }

    /**
     * 删除商品库存
     */
    @PreAuthorize("@ss.hasPermi('biz:bizStock:remove')")
    @Log(title = "商品库存", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(bizStockService.deleteBizStockByIds(ids));
    }


    /**
     * 导出商品库存列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizStock:export')")
    @Log(title = "商品库存", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizStock bizStock) {
        List<BizStock> list = bizStockService.findList(bizStock);
        ExcelUtil<BizStock> util = new ExcelUtil<BizStock>(BizStock.class);
        return util.exportExcel(list, "商品库存数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

}
